package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.*;
import cn.wolfcode.wolf2w.service.*;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("destinations")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;

    @Autowired
    private IRegionService regionService;

    @Autowired
    private IStrategyCatalogService strategyCatalogService;

    @Autowired
    private IStrategyService strategyService;

    @Autowired
    private ITravelService travelService;

    @Autowired
    private IStrategyThemeService strategyThemeService;

    @GetMapping("hotRegion")
    public Object hotRegion(){
        // 把查询到的热门城市返回给前端vue
        List<Region> regions = regionService.queryHot();
        // 返回一个JsonResult 对象,因为前端是调用返回一个JsonResult 的data属性
        return JsonResult.success(regions);
    }

    @GetMapping("search")
    public Object search(String regionId){
        return JsonResult.success(destinationService.queryDestByRegionId(regionId));
    }

    @GetMapping("toasts")
    public Object toasts(String destId){
        return JsonResult.success(destinationService.queryToasts(destId));
    }

    @GetMapping("detail")
    public Object detail(String id){
        Destination destination = destinationService.get(id);
        return JsonResult.success(destination);
    }

    @GetMapping("catalogs")
    public Object catalogs(String destId){
        return JsonResult.success(strategyCatalogService.queryCatalogByDestId(destId));
    }

   @GetMapping("strategies/viewnumTop3")
    public Object viewnumTop3(String destId){

       List<Strategy> list = strategyService.queryViewnumTop3(destId);
       return JsonResult.success(list);
   }

    @GetMapping("travels/viewnumTop3")
    public Object travelsViewnumTop3(String destId){
        List<Travel> list = travelService.queryViewnumTop3(destId);
        return JsonResult.success(list);
    }
}
